﻿/****************************************************************
  Author:  Ievgenii Nazaruk, ievgenii.nazaruk@gmail.com 
 License:  Microsoft Public License (Ms-PL)
          ( http://www.opensource.org/licenses/ms-pl.html or
            http://www.microsoft.com/opensource/licenses.mspx )
*****************************************************************/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Net;

namespace WebLayer
{
    public class SiteWebPage: WebPage
    {
        public LoginToken LoginToken = null;

        public SiteWebPage(String pageName, Uri uri):
            base(pageName,uri)
        { 
        }

        public override void  Request()
        {
            base.Request();
        }

        override protected void OnRequest(HttpWebRequest request)
        {
            base.OnRequest(request);

            if(LoginToken != null)
            {
                request.CookieContainer = LoginToken.Cookies;
            }
        }

        override protected void  OnResponse(HttpWebRequest request, HttpWebResponse response)
        {
            base.OnResponse(request, response);

            if (PageContent.Length == 0)
            {
                //if response is empty - we requested page without logging in
                throw new UnauthorizedAccessException();
            }
        }


    }
}
